const Service = require('../../../core/service/ApiService');

class SvcItemSvc extends Service {

    //搜索服务项目
    async searchItem(name) {
        const dao = this.service.admin.svcitem.dao;
        const item = await dao.searchItemId(name);
        const date = this.helper.YMDhms(new Date());
        if(!item){
            throw new this.error.BusinessError('不存在该项目')
        }
        else{
            return {
                list: {
                    svc_item_id: item.svc_item_id,
                    name: item.name,
                    count: await dao.searchAmount(item.svc_item_id, date)
                }
            }
        }
    }

    //编辑服务项目
    async editItem(id, name) {
        return this.service.admin.svcitem.dao.editItem(id, name);
    }

    //删除服务项目
    async delete(id) {
        return this.service.admin.svcitem.dao.delete(id);
    }

    //添加服务项目
    async addItem(name) {
        return this.service.admin.svcitem.dao.addItem(name);
    }

    //服务项目查看统计
    async viewStatistic(id) {
        const date = this.helper.YMDhms(new Date());
        return {
            svc_cnt_list: await this.service.admin.svcitem.dao.viewStatistic(id, date)
        }
    }
}

module.exports = SvcItemSvc;
